/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.mc.client;

import com.xy.biz.mc.domain.req.MessagePushFromRequest;
import com.xy.biz.mc.domain.req.MessagePushRequest;
import com.xy.biz.mc.domain.req.MessagePushRequest2;
import com.xy.biz.mc.domain.resp.MessagePushResponse;
import com.xy.lang.domain.Result;

import java.util.Collection;
import java.util.Objects;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 消息推送客户端
 * 
 * @author zsp
 * @date 2021-2-25
 */
public interface MessagePushClient {

    /**
     * 推送消息给指定用户
     *
     * @param request
     * @return
     */
    Result<MessagePushResponse> send(MessagePushRequest request);

    default Result<MessagePushResponse> send2(MessagePushRequest2 request2) {
        MessagePushRequest request = new MessagePushRequest();
        request.setToId(request2.getToId());
        //request.setData(request2.getPayload());
        return send(request);
    }

    /**
     * 推送消息给指定用户分组
     *
     * @param request
     * @return
     */
    Result<MessagePushResponse> sendToGroup(MessagePushRequest request);

    /**
     * 用户推送消息给其他指定用户
     *
     * @param request
     * @return
     */
    Result<MessagePushResponse> sendByFrom(MessagePushFromRequest request);

    /**
     * 用户推送消息给指定用户分组
     *
     * @param request
     * @return
     */
    Result<MessagePushResponse> sendByFromToGroup(MessagePushFromRequest request);

    /**
     * 推送消息给指定用户
     *
     * @param requests
     * @return
     */
    Result<MessagePushResponse> sendAll(Collection<MessagePushRequest> requests);

    /**
     * 推送消息给指定用户分组
     *
     * @param requests
     * @return
     */
    Result<MessagePushResponse> sendAllToGroup(Collection<MessagePushRequest> requests);

    /**
     * 用户推送消息给其他指定用户
     *
     * @param requests
     * @return
     */
    Result<MessagePushResponse> sendAllByFrom(Collection<MessagePushFromRequest> requests);

    /**
     * 用户推送消息给指定用户分组
     *
     * @param requests
     * @return
     */
    Result<MessagePushResponse> sendAllByFromToGroup(Collection<MessagePushFromRequest> requests);

    /**
     * 推送消息给指定用户
     *
     * @param request
     * @param threadPoolExecutor
     * @return
     */
    default Future<Result<MessagePushResponse>> sendAsync(MessagePushRequest request, ThreadPoolExecutor threadPoolExecutor) {
        Objects.requireNonNull(threadPoolExecutor);
        return threadPoolExecutor.submit(() -> send(request));
    }

    /**
     * 推送消息给指定用户分组
     *
     * @param request
     * @param threadPoolExecutor
     * @return
     */
    default Future<Result<MessagePushResponse>> sendToGroupAsync(MessagePushRequest request, ThreadPoolExecutor threadPoolExecutor) {
        Objects.requireNonNull(threadPoolExecutor);
        return threadPoolExecutor.submit(() -> sendToGroup(request));
    }

    /**
     * 用户推送消息给其他指定用户
     *
     * @param request
     * @param threadPoolExecutor
     * @return
     */
    default Future<Result<MessagePushResponse>> sendByFromAsync(MessagePushFromRequest request, ThreadPoolExecutor threadPoolExecutor) {
        Objects.requireNonNull(threadPoolExecutor);
        return threadPoolExecutor.submit(() -> sendByFrom(request));
    }

    /**
     * 用户推送消息给指定用户分组
     *
     * @param request
     * @param threadPoolExecutor
     * @return
     */
    default Future<Result<MessagePushResponse>> sendByFromToGroupAsync(MessagePushFromRequest request, ThreadPoolExecutor threadPoolExecutor) {
        Objects.requireNonNull(threadPoolExecutor);
        return threadPoolExecutor.submit(() -> sendByFromToGroup(request));
    }

    /**
     * 推送消息给指定用户
     *
     * @param requests
     * @param threadPoolExecutor
     * @return
     */
    default Future<Result<MessagePushResponse>> sendAllAsync(Collection<MessagePushRequest> requests, ThreadPoolExecutor threadPoolExecutor) {
        Objects.requireNonNull(threadPoolExecutor);
        return threadPoolExecutor.submit(() -> sendAll(requests));
    }

    /**
     * 推送消息给指定用户分组
     *
     * @param requests
     * @param threadPoolExecutor
     * @return
     */
    default Future<Result<MessagePushResponse>> sendAllToGroupAsync(Collection<MessagePushRequest> requests, ThreadPoolExecutor threadPoolExecutor) {
        Objects.requireNonNull(threadPoolExecutor);
        return threadPoolExecutor.submit(() -> sendAllToGroup(requests));
    }

    /**
     * 用户推送消息给其他指定用户
     *
     * @param requests
     * @param threadPoolExecutor
     * @return
     */
    default Future<Result<MessagePushResponse>> sendAllByFromAsync(Collection<MessagePushFromRequest> requests, ThreadPoolExecutor threadPoolExecutor) {
        Objects.requireNonNull(threadPoolExecutor);
        return threadPoolExecutor.submit(() -> sendAllByFrom(requests));
    }

    /**
     * 用户推送消息给指定用户分组
     *
     * @param requests
     * @param threadPoolExecutor
     * @return
     */
    default Future<Result<MessagePushResponse>> sendAllByFromToGroupAsync(Collection<MessagePushFromRequest> requests, ThreadPoolExecutor threadPoolExecutor) {
        Objects.requireNonNull(threadPoolExecutor);
        return threadPoolExecutor.submit(() -> sendAllByFromToGroup(requests));
    }
	
}
